package com.itcast.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.itcast.yygh.cmn.mapper.DictMapper;
import com.itcast.yygh.model.model.cmn.Dict;
import com.itcast.yygh.model.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 数据字典数据导入监听器
 */
@Component
public class DictListener extends AnalysisEventListener<DictEeVo> {
    //引入mapper的依赖
    @Resource
    private DictMapper dictMapper;

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //1.需要创建新的dict对象
        Dict dict = new Dict();
        //2.拷贝vo中的数据到dict对象中
        BeanUtils.copyProperties(dictEeVo,dict);
        //3.调用保存方法进行数据的保存
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
